package com.leeh.jsontest;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Liheng on 2017-04-14.
 */

public class SpinnerAdapter extends ArrayAdapter<SpinnerContent> {
    private Context context;
    private int resource;
    private List<SpinnerContent> spinnerContents;
    public SpinnerAdapter(Context context, int resource, List<SpinnerContent> objects) {
        super(context, resource, objects);
        this.context = context;
        this.resource = resource;
        this.spinnerContents = objects;
    }

    @NonNull
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       convertView  = LayoutInflater.from(context).inflate(resource,null);
        TextView txtName = (TextView) convertView.findViewById(R.id.teacher_name);
        txtName.setText(spinnerContents.get(position).getValue());
        txtName.setTag(spinnerContents.get(position).getKey());
        return convertView;
    }
}
